package 网络通信2;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.Reader;
import java.io.InputStreamReader;

public class Serve {
	public static void main(String[] args) throws Exception
	{
		System.out.println("服务端启动了");
		//1.创建服务端程序的端口
		ServerSocket socket=new ServerSocket(8888);
		//2.创建管道用来接收数据
		Socket s=socket.accept();
		InputStream is=s.getInputStream();
		DataInputStream dis=new DataInputStream(is);
		while(true) {
			try {
		System.out.println(dis.readUTF());}
			catch(Exception e)
			{
				System.out.println(s.getLocalAddress().getHostAddress()+"已退出");
				socket.close();
				break;
			}
		}
	}
}